package 三六零机试;

import 阿里巴巴机试题目.Tools;

import java.util.Scanner;

//5 5
//2 1 2 3
//2 1 3
//
//0 0 0 3 3 3
//0 0 0 3 3 3
//1 2 2 4 5 5
//1 2 2 4 5 5
//2 3 4 5 6 7
//2 3 4 5 6 7
//
//7

public class ThreeSixZero第二题 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int m = sc.nextInt();
            int n = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int z = sc.nextInt();
            getMaxMoney(m, n, a, b, c, d, x, y, z);
        }
        sc.close();
    }

    private static void getMaxMoney(int m, int n, int a, int b, int c, int d, int x, int y, int z) {
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 0; i <= m; i++) {
            for (int j = 0; j <= n; j++) {
                int mx = 0, my = 0, mz = 0;
                mx = i - a >= 0 && j - b >= 0 ? dp[i - a][j - b] + x : mx;
                my = i - c >= 0 ? dp[i - c][j] + y : my;
                mz = j - d >= 0 ? dp[i][j - d] + z : mz;
                dp[i][j] = Math.max(Math.max(mx, my), mz);
            }
        }
        new Tools().print2DArray(dp);
        System.out.println(dp[m][n]);
    }
}
